Designing and evaluating an online reinforcement learning agent for physical exercise recommendations in N-of-1 trials¶
This notebook is used to evaluate the performance for the RL agent using data from the simulate_data.ipynb notebook.
Imports¶
In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
# Generic Imports
import pandas as pd
import pandas
import seaborn as sns
import matplotlib.pylab as plt
import numpy as np
import arviz as az
import arviz
import numpy
import hvplot
import holoviews
import random
import itertools
from tqdm.notebook import tqdm
from bokeh.io import show
from bokeh.layouts import column
import jsonpickle
In [3]:
# Simulation Library Imports
from nof1rl4endo import *
Load from disk¶
In [4]:
## Load jsonpickle from disk:
parallel = True
if parallel:
appendices = [f"_parallel_scenario_{index}" for index in range(7)]
else:
appendices = [""]
calculated_series = []
config_to_simulation_data = {}
filenames = [f"../data/2023-11-08-data{appendix}.json" for appendix in appendices]
for filename in filenames:
with open(filename, "r") as file:
new_calculated_series, new_config_to_simulation_data = jsonpickle.decode(file.read())
calculated_series.extend(new_calculated_series)
config_to_simulation_data.update(new_config_to_simulation_data)
Analysis¶
Allocations¶
In [5]:
titles = [
f"{entry['result'].simulations[0].model}, {entry['result'].simulations[0].policy}"
for entry in calculated_series
]
def plot_allocations(calculated_series, titles, treatment_name):
panels = [
entry["result"].plot_allocations(treatment_name) for entry in calculated_series
]
for title, panel in zip(titles, panels):
panel.opts(title=title)
return holoviews.Layout(panels).cols(1)
plot_allocations(calculated_series, titles, treatment_name="selection_index")
/opt/homebrew/Caskroom/miniconda/base/envs/mt/lib/python3.11/site-packages/holoviews/plotting/bokeh/plot.py:987: UserWarning: found multiple competing values for 'toolbar.active_drag' property; using the latest value layout_plot = gridplot( /opt/homebrew/Caskroom/miniconda/base/envs/mt/lib/python3.11/site-packages/holoviews/plotting/bokeh/plot.py:987: UserWarning: found multiple competing values for 'toolbar.active_scroll' property; using the latest value layout_plot = gridplot(
Out[5]: